<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="java,面试,学习,">










<meta name="description" content="Object的方法 equals(): 比较两个对象，默认时进行地址的比较；  hashCode(): 获取对象的散列值，当需要比较多个对象时，使用equals方法耗时，hashCode可以大大节省时间；  toString(): 将对象转换为字符串，默认输出为：对象路径@对象内存地址  clone(): 克隆对象，对象需要实现Cloneable接口，否则会出现CloneNotSupportedE">
<meta name="keywords" content="java,面试,学习">
<meta property="og:type" content="article">
<meta property="og:title" content="Java 笔记（一）">
<meta property="og:url" content="http://yoursite.com/2019/11/06/Java-笔记（一）/index.html">
<meta property="og:site_name" content="平凡小札">
<meta property="og:description" content="Object的方法 equals(): 比较两个对象，默认时进行地址的比较；  hashCode(): 获取对象的散列值，当需要比较多个对象时，使用equals方法耗时，hashCode可以大大节省时间；  toString(): 将对象转换为字符串，默认输出为：对象路径@对象内存地址  clone(): 克隆对象，对象需要实现Cloneable接口，否则会出现CloneNotSupportedE">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-11-06T12:06:05.369Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java 笔记（一）">
<meta name="twitter:description" content="Object的方法 equals(): 比较两个对象，默认时进行地址的比较；  hashCode(): 获取对象的散列值，当需要比较多个对象时，使用equals方法耗时，hashCode可以大大节省时间；  toString(): 将对象转换为字符串，默认输出为：对象路径@对象内存地址  clone(): 克隆对象，对象需要实现Cloneable接口，否则会出现CloneNotSupportedE">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/11/06/Java-笔记（一）/">





  <title>Java 笔记（一） | 平凡小札</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <a href="https://github.com/SimFG/SimFG.github.io"><img style="position: absolute; top: 0; right: 0;" width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_white_ffffff.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">平凡小札</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/06/Java-笔记（一）/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="影决">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="平凡小札">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java 笔记（一）</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-06T20:01:52+08:00">
                2019-11-06
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java-笔记/" itemprop="url" rel="index">
                    <span itemprop="name">Java 笔记</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="Object的方法"><a href="#Object的方法" class="headerlink" title="Object的方法"></a>Object的方法</h2><ol>
<li><p>equals(): 比较两个对象，默认时进行地址的比较；</p>
</li>
<li><p>hashCode(): 获取对象的散列值，当需要比较多个对象时，使用equals方法耗时，hashCode可以大大节省时间；</p>
</li>
<li><p>toString(): 将对象转换为字符串，默认输出为：对象路径@对象内存地址</p>
</li>
<li><p>clone(): 克隆对象，对象需要实现Cloneable接口，否则会出现CloneNotSupportedException，同时注意区分对象赋值与对象克隆、浅克隆与深克隆；</p>
</li>
<li><p>getClass(): 获取当前对象的Class类，主要用于反射；</p>
</li>
<li><p>notify()/notifyAll(): 唤醒在此对象监视器上的线程；</p>
</li>
<li><p>wait()/waitAll(): 当前线程进入等待；</p>
</li>
<li><p>finalize(): 当前对象回收时执行该方法，但是不能保证一定会执行；</p>
</li>
<li><p>native方法和非native方法：native方法并不是使用java语言进行实现，而是由jvm内部实现，也就是使用c++语言进行实现的，根据不同主机执行的方式不一样，另外native方法一般比非native方法执行快；</p>
</li>
</ol>
<p><a href="https://blog.csdn.net/qq_34115898/article/details/83270519" target="_blank" rel="noopener">参考博客</a></p>
<h2 id="Object的wait方法与Thread的sleep方法的区别"><a href="#Object的wait方法与Thread的sleep方法的区别" class="headerlink" title="Object的wait方法与Thread的sleep方法的区别"></a>Object的wait方法与Thread的sleep方法的区别</h2><ol>
<li><p>wait()来自于Object类而sleep来自于Thread类</p>
</li>
<li><p>sleep没有释放锁，但是wait释放了锁（使得其他线程可以使用同步控制块或者方法锁）</p>
</li>
<li><p>wait，waitAll，notify和notifyAll只能在同步控制方法或者同步控制块使用（在synchronized方法或者block中），而sleep能在各个地方使用</p>
</li>
<li><p>sleep必须捕获异常，但是wait不用</p>
</li>
<li><p>sleep让一个线程睡眠，等待一段时间后，自动醒来进入可运行状态，不会马上进入运行状态，因为线程调度机制恢复线程也需要时间。如果调用interrup方法，则会抛出InterruptedException。如果不捕获这个异常，那么会进入TERMINATED状态。如果捕获这个异常，那么可以在catch中继续执行后面的代码。如果线程并不处于wait，sleep，join状态时，调用interrupt方法线程不会抛出InterruptedException。</p>
</li>
<li><p>sleep是静态方法，只会让当前线程sleep，t.sleep()并不会让t进入sleep</p>
</li>
</ol>
<p><a href="https://www.cnblogs.com/ylxn/p/10395315.html" target="_blank" rel="noopener">参考博客</a></p>
<h2 id="异常"><a href="#异常" class="headerlink" title="异常"></a>异常</h2><p>异常的顶级父类：Throwable，其实现了Serializable接口；</p>
<p>Error类和Exception类：继承Throwable，Error表示程序运行环境出现异常，如OutOfMemoryError,StackOverFlowError；Exception表示程序运行时出现异常，由显式异常（RuntimeException）和隐式异常（IOException、SQLException）之分；</p>
<p>常见异常类：</p>
<pre><code>1. ArithmeticException： 除数为0；

2. ClassCastException: 类型转换错误；

3. NullPointException: 访问为初始化对象的方法；

4. IndexOutOfBoundsException: 数组下标越界或者字符串访问越界；

5. ClassNotFoundException: 未找到指定类或者接口；

6. NumberFormatException： 字符转换为数字类型异常，如Integer.valueOf(&quot;a&quot;);

7. CloneNotSupportedException: 使用对象的克隆方法，但是对象没有实现Cloneable接口；

8. InterruptedException: 线程中断异常，如果在线程处于sleep/wait/join状态下，调用interrupt方法则会导致该异常，在调用Thread.sleep()方法时必须捕捉该异常；</code></pre>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
            <a href="/tags/面试/" rel="tag"># 面试</a>
          
            <a href="/tags/学习/" rel="tag"># 学习</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/10/31/工作日记-2019-10-13/" rel="next" title="工作日记:2019-10-13">
                <i class="fa fa-chevron-left"></i> 工作日记:2019-10-13
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/11/07/LeetCode-1-10/" rel="prev" title="LeetCode 1-10">
                LeetCode 1-10 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">影决</p>
              <p class="site-description motion-element" itemprop="description">在平凡的生活里做着平凡的事，愿我造就不平凡的未来。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">14</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Object的方法"><span class="nav-number">1.</span> <span class="nav-text">Object的方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Object的wait方法与Thread的sleep方法的区别"><span class="nav-number">2.</span> <span class="nav-text">Object的wait方法与Thread的sleep方法的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#异常"><span class="nav-number">3.</span> <span class="nav-text">异常</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">影决</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>
</html>
